<?php

defined('__MAPEXEC__') or die('No direct access allowed');

/**
 * Denotes a map Point Of Interest (POI). Sometimes called a map marker or pin.
 *
 * Created on Dec 29, 2008
 * @author      Greg Burghardt
 * @copyright   Copyright &copy; 2008, Greg Burghardt
 */
class Maps_Map_POI extends Maps_LocationManager {
  
  private $address = '';
  private $contacts = array();
  private $description = '';
  private $enableDirections = true;
  private $iconName = '';
  private $image = '';
  private $imageHeight = 0;
  private $imageWidth = 0;
  private $coords = null;
  private $name = '';
  private $title = '';
  private $url = '';
  private $urlText = 'more info &raquo;';
  private $website = '';
  private $websiteText = 'view website &raquo;';

  /**
   * Class constructor
   * @param   Maps_LatLng   Latitude/longitude object
   * @param   string        Name text for this point of interest
   * @param   string        Icon name
   * @return  void
   */
  public function __construct(Maps_LatLng $coords, $name, $iconName='') {
    $this->setLatLng($coords);
    $this->setName($name);
    $this->setIconName($iconName);
  }
  
  /**
   * Adds a contact for this point of interest.
   * @param   string  Contact info, like phone numbers, email addresses, etc.
   * @return  int     Index at which this info was inserted, or -1 if not inserted.
   */
  public function addContact($str) {
    if ( !empty($str) ) {
      $this->contacts[] = (string) $str;
      return count($this->contacts) - 1;
    }
    return -1;
  }
  
  /**
   * Disables directions for this point of interest
   * @param   void
   * @return  void
   */
  public function disableDirections() {
    $this->enableDirections = false;
  }
  
  /**
   * Enables directions for this point of interest
   * @param   void
   * @return  void
   */
  public function enableDirections() {
    $this->enableDirections = true;
  }
  
  /**
   * Gets the physical address for this point of interest.
   * @param   void
   * @return  string  Street address text
   */
  public function getAddress() {
    if ( empty($this->address) && $this->hasLocation() ) {
      $this->address = (string) $this->location;
    }
    return $this->address;
  }
  
  /**
   * Gets an individual piece of contact information.
   * @param   int     Index of contact info to get.
   * @return  string  Contact info, or null if not found.
   */
  public function getContact($index) {
    if ( empty($this->contacts[$index]) ) {
      return null;
    } else {
      $this->contacts[$index];
    }
  }
  
  /**
   * Gets the list of contact information for this point of interest.
   * @param   void
   * @return  array   Contact info, like phone numbers and email addresses.
   */
  public function getContacts() {
    return $this->contacts;
  }
  
  /**
   * Gets the description for this point of interest.
   * @param   void
   * @return  string  Description text.
   */
  public function getDescription() {
    return $this->description;
  }
  
  /**
   * Gets the icon name for this point of interest.
   * @param   void
   * @return  string  Icon name
   */
  public function getIconName() {
    return $this->iconName;
  }
  
  /**
   * Gets the image for this point of interest.
   * @param   void
   * @return  string  Image URL
   */
  public function getImage() {
    return $this->image;
  }
  
  /**
   * Gets the image height for this point of interest.
   * @param   void
   * @return  integer   Image height in pixels
   */
  public function getImageHeight() {
    return $this->imageHeight;
  }
  
  /**
   * Gets the image width for this point of interest.
   * @param   void
   * @return  integer   Image width in pixels
   */
  public function getImageWidth() {
    return $this->imageWidth;
  }
  
  /**
   * Gets the latitude of this point of interest.
   * @param   void
   * @return  double  Degrees latitude
   */
  public function getLat() {
    return $this->coords->getLat();
  }
  
  /**
   * Returns the latitude/longitude object for this POI
   * @param   void
   * @return  Maps_LatLng   Latitude and longitude object
   */
  public function getLatLng() {
    return $this->coords;
  }
  
  /**
   * Gets the longitude of this point of interest.
   * @param   void
   * @return  double  Degrees longitude
   */
  public function getLng() {
    return $this->coords->getLng();
  }
  
  /**
   * Gets name of this point of interest.
   * @param   void
   * @return  string  POI name
   */
  public function getName() {
    return $this->name;
  }
  
  /**
   * Gets the title text of this point of interest.
   * @param   void
   * @return  string  Title text
   */
  public function getTitle() {
  	return $this->title;
  }
  
  /**
   * Gets the URL of a "more info" page on this web site for this point of interest.
   * @param   void
   * @return  string  Uniform Resource Indicator
   */
  public function getURL() {
    return $this->url;
  }
  
  /**
   * Gets the text for the "more info" link at end of description.
   * @param   void
   * @return  string  "More info" link text
   */
  public function getUrlText() {
    return $this->urlText;
  }
  
  /**
   * Gets the website URL for this point of interest.
   * @param   void
   * @return  string  Uniform Resource Indicator
   */
  public function getWebsite() {
    return $this->website;
  }
  
  /**
   * Gets the text for the website link.
   * @param   void
   * @return  string  Web site link text
   */
  public function getWebsiteText() {
    return $this->websiteText;
  }
  
  /**
   * Sets the description for this point of interest.
   * @param   string  Description text
   * @return  void
   */
  public function setDescription($str) {
    if ( !empty($str) ) {
      $this->description = (string) $str;
    }
  }
  
  /**
   * Gets the title text of this point of interest.
   * @param   void
   * @return  string  Title text
   */
  public function setIconName($str='') {
    if ( !empty($str) ) {
      $this->iconName = (string) $str;
    }
  }
  
  /**
   * Sets the thumbnail image URL for this point of interest.
   * @param   string  URL to an image
   * @return  void
   */
  public function setImage($url, $width, $height) {
    if ( !empty($url) && $width > 0 && $height > 0 ) {
      $this->image = (string) $url;
      $this->imageHeight = round($height);
      $this->imageWidth = round($width);
    }
  }
  
  /**
   * Sets the latitude and longitude where this POI appears.
   * @param   Maps_LatLng   Latitude and longitude object
   * @return  void
   */
  public function setLatLng(Maps_LatLng $coords) {
    $this->coords = $coords;
  }
  
  /**
   * Sets the title text for this POI.
   * @param   string  Name text
   * @return  void
   */
  public function setName($str='') {
    if ( !empty($str) ) {
      $this->name = (string) $str;
    }
  }
  
  /**
   * Sets the title text for this POI.
   * @param   string  Title text
   * @return  void
   */
  public function setTitle($str='') {
    if ( !empty($str) ) {
      $this->title = (string) $str;
    }
  }
  
  /**
   * Sets the URL for a "more info" page on this website.
   * @param   string  URL to a page on this website with more information.
   * @return  void
   */
  public function setURL($url) {
    if ( !empty($url) ) {
      $this->url = (string) $url;
    }
  }
  
  /**
   * Text for the "more info" link at the end of the description for this POI.
   * @param   string  "More info" link text
   * @return  void
   */
  public function setUrlText($str) {
    if ( !empty($str) ) {
      $this->urlText = (string) $str;
    }
  }
  
  /**
   * URL for the external website associated with this POI.
   * @param   string  URL to an external website.
   * @return  void
   */
  public function setWebsite($url) {
    $url = (string) $url;
    if ( !empty($url) ) {
      if ( !preg_match('/^http:\/\/|https:\/\//', $url) ) {
        $url = 'http://' . $url;
      }
      $this->website = $url;
    }
  }
  
  /**
   * Text for the external website link for this POI.
   * @param   string  Website link text
   * @return  void
   */
  public function setWebsiteText($str) {
    if ( !empty($str) ) {
      $this->websiteText = (string) $str;
    }
  }
  
}
?>